package leetcode;

import java.util.Scanner;

/**
 * description:
 * author:zt
 * date:2021-08-07
 */
public class Solution2  {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt();
        boolean[] res = new boolean[T];
        for (int i = 0; i < T; i++) {
            int N = sc.nextInt(); //N名运动员
            int M = sc.nextInt(); //M行数据
            int[][] c = new int[M][];
            for (int i1 = 0; i1 < M; i1++) {
                int count = sc.nextInt(); //本次记得的运动员数量
                c[i1] = new int[count];
                for (int i2 = 0; i2 < count; i2++) {
                    c[i1][i2] = sc.nextInt();
                }
            }
            res[i] = test(c,N);
        }
        for (int i = 0; i < res.length; i++) {
            if (!res[i]) System.out.println("NO");
        }
    }

    public static boolean test(int[][] nums,int count){
        boolean[][] check = new boolean[count][count];
        for (int i = 0; i < check.length; i++) {
            check[i][i] = true;
        }
        //行
        for (int i = 0; i < nums.length; i++) {
            int left = 0;
            while (left<nums[i].length-1){
                for (int j = left+1; j < nums[i].length; j++) {
                    if (nums[i][j]==0) break;
                    check[nums[i][left]-1][nums[i][j]-1] = true;
                    check[nums[i][j]-1][nums[i][left]-1] = true;
                }
            }
        }
        for (int i = 0; i < check.length; i++) {
            for (int j = 0; j < check[0].length; j++) {
                if (!check[i][j]) return false;
            }
        }
        return true;
    }
}
